package com.test.exam.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.test.exam.commons.PageHelper;
import com.test.exam.dao.StudentDao;
import com.test.exam.domain.Student;

@Service
public class StudentService {
	private final int STUDENT_ROW_PER_PAGE = 3; 
	
	@Autowired
	private StudentDao studentDao;
	
	// 한 반의 목록
	public List<Student> getStudentsByBanIdx(int banIdx){
		return studentDao.getStudentsByBanIdx(banIdx);
	}
	
	// end page
	public int getEndPage(int banIdx){
		int count = studentDao.getStudentCountByBanIdx(banIdx);
		if(count == 0){
			return 0;
		}
		return (int)(Math.ceil((float)count/(float)STUDENT_ROW_PER_PAGE));
	}
	
	// 학생입력
	public int addStudent(Student student){
		return studentDao.addStudent(student);
	}
	
	public List<HashMap> getStudentsByCurrentPage(int banIdx, int currentPage){
		PageHelper pageHelper = new PageHelper();
		pageHelper.setRowPerPage(STUDENT_ROW_PER_PAGE);
		pageHelper.setStartRow(currentPage);
		return studentDao.getStudentsByCurrentPage(banIdx, pageHelper);
	}
}















